Various aspects of the present invention relate generally to the interaction between native code and Java, and more particularly, to the efficient transfer of Java Native Interface calls across a Java Native Interface boundary.
A Java Virtual Machine (JVM) is an abstract computing machine that enables computer programs and data structures to use a virtual machine model for the execution of other computer programs and scripts. In general, Java Virtual Machines allow system designers to improve system scalability and exploit the capabilities of underlying physical machine(s), while providing isolation for applications executing in corresponding Java Virtual Machine instances.
While application isolation is often desirable, there are situations where a Java application requires functionality that is not provided by a standard Java Application Programming Interface (API). Accordingly, the Java Native Interface (JNI) provides a programming framework that allows interaction between non-Java languages and a Java Virtual Machine in a clearly defined manner. The Java Native Interface also establishes a clean boundary between native code and the Java Virtual Machine, making it possible to provide separate execution environments for the two components.
Thus, the pairing of a Java Native Interface and a Java Virtual Machine facilitates Java code running in a Java Virtual Machine to call and be called by native applications and libraries written in other languages. As a result, legacy applications can access the services available to Java. Correspondingly, Java applications can utilize native methods to handle situations that cannot be addressed entirely with Java code. In practice however, native code may be compiled with a first calling convention, e.g., OSLINK, which uses an upward growing stack. To the contrary, the Java Virtual Machine, and hence Java Native Interface implementations, may be compiled with a second calling convention, such as XPLINK, which uses a downward growing stack. As such, stack-swapping services may be required to transition between the two calling conventions in order for Java code to call and be called by certain native applications.